////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.more;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BaseActivity;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;

/**
 * 
 * @author haibo
 * 
 *  for top 20  category;
 *
 */
public class Top20StockListActivity extends BaseActivity implements
	OnClickListener
{
	protected static final String	TAG			= Top20StockListActivity.class
												.getSimpleName();
	private Button				_toolBtnReturn;
	private Button				_classBtnStock_raises;
	private Button				_classBtnStock_decline;
	private Button				_classBtnStock_turnover;
	private Button				_classBtnStock_volume;
	private Button				_classBtnStock_warrant_raises;
	private Button				_classBtnStock_warrant_decline;
	private Button				_classBtnStock_warrant_turnover;
	private Button				_classBtnStock_warrant_volume;
	private static String		_currentTag	= "STOCKLIST_NetGainers";
	private static String		_btnCaption;

	@Override
	public void onClick(View v)
	{
		Class<? extends Activity> cls = /*PortfolioActivity.class*/BMPTop20Activity.class;
		// BMP Mode  by ouyangzhihui 2011-10-13
//		if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
//		{
//			cls = BMPTop20Activity.class;
//		}
		switch (v.getId())
		{
			case R.id.more_returnbtn:
				((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, "");
//				((ITDLApplication) getApplicationContext()).putString(CommonDefn.TOP_BAR_TITLE, _btnCaption);

				Intent intent = new Intent(getApplicationContext(), cls);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(cls, intent);
				break;
			default:
				if (v instanceof Button && v.getTag() != null)
				{
					if (v.getTag().toString().matches(CommonDefn.STOCK_LIST_TOP20_REG))
					{
						((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, v.getTag().toString());

						String title = getResources().getString(R.string.top_20_sector) + ((Button) v).getText().toString();
						((ITDLApplication) getApplicationContext()).putString(CommonDefn.TOP_BAR_TITLE, title);
						_btnCaption = title;
						
						TDStockLog.d(TAG, "ready to go to PortfolioActivity, and the tag is :" + v.getTag().toString());
						_currentTag = v.getTag().toString();

						Intent forwarding = new Intent(getApplicationContext(), cls);
						forwarding.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
						SwitchForwardActivity(cls, forwarding);
					}
				}
				break;
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.top20_stock_list);
		resetMinHeightOnWorkCenter();
		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		_toolBtnReturn.setOnClickListener(this);

		_classBtnStock_raises = (Button) findViewById(R.id.top_20_stock_raises);
		_classBtnStock_raises.setOnClickListener(this);

		_classBtnStock_decline = (Button) findViewById(R.id.top_20_stock_decline);
		_classBtnStock_decline.setOnClickListener(this);

		_classBtnStock_turnover = (Button) findViewById(R.id.top_20_stock_turnover);
		_classBtnStock_turnover.setOnClickListener(this);

		_classBtnStock_volume = (Button) findViewById(R.id.top_20_stock_volume);
		_classBtnStock_volume.setOnClickListener(this);

		_classBtnStock_warrant_raises = (Button) findViewById(R.id.top_20_stock_warrant_raises);
		_classBtnStock_warrant_raises.setOnClickListener(this);

		_classBtnStock_warrant_decline = (Button) findViewById(R.id.top_20_stock_warrant_decline);
		_classBtnStock_warrant_decline.setOnClickListener(this);

		_classBtnStock_warrant_turnover = (Button) findViewById(R.id.top_20_stock_warrant_turnover);
		_classBtnStock_warrant_turnover.setOnClickListener(this);

		_classBtnStock_warrant_volume = (Button) findViewById(R.id.top_20_stock_warrant_volume);
		_classBtnStock_warrant_volume.setOnClickListener(this);

	}

	@Override
	protected void onPause()
	{
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onRestart()
	{
		// TODO Auto-generated method stub
		super.onRestart();
	}

	@Override
	protected void onResume()
	{
		// TODO Auto-generated method stub
		super.onResume();

		resetReturnBtnCaption();
	}

	private void resetReturnBtnCaption()
	{
		if (_btnCaption == null)
		{
			_btnCaption = getResources()
					.getString(R.string.top_20_stock_net);
			((ITDLApplication) getApplicationContext()).putString(
					CommonDefn.TOP_BAR_TITLE, _btnCaption);
		}

		_toolBtnReturn.setText(_btnCaption);

	}
	
	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return MoreGroup.GetActivityGroupHostControl();
	}
	
	
	

}
